<?php
	include_once("../conexao.php");
	abreConec();
	
	$sql_ano = "SELECT anoPub FROM materias WHERE ativo=1 GROUP BY anoPub ORDER BY anoPub ASC";
	$ano_qry = mysql_query($sql_ano);
	
	$sqlMidia = "SELECT id_materia, tipo_midia FROM materias WHERE ativo=1 GROUP BY tipo_midia ORDER BY tipo_midia ASC";
	$midia_qry = mysql_query($sqlMidia);
		
	if(isset($_REQUEST['f']) && $_REQUEST['f']==1){
		if(!empty($_REQUEST['fa'])){
			$filtroAno = $_REQUEST['fa'];
			$filAno = "AND anoPub='$filtroAno' ";
		}else $filAno = "vázio";
		
		if(!empty($_REQUEST['fm'])){
			$filtroMidia = $_REQUEST['fm'];
			$filMidia = "AND tipo_midia='$filtroMidia' ";
		}else $filMidia = "vázio";
	}
	
	echo "Campo Ano: ".$filAno."<br />";
	echo "Campo Tipo: ".$filMidia;
?>
<!DOCTYPE html>
<html lang="pt-BR">
	<head>
		<meta charset="utf-8">
		<title>Teste de formulário</title>
		<style type="text/css">
			.toolbar{
				padding:18px 15px 0 15px;
				background-color:#F5F5F5;
				border:1px solid #999;
				border-radius: 3px;
				-webkit-border-radius: 3px;
			}
		</style>
	</head>
	<body>
		<h3 class="muted">Nossas publicações</h3>
		<div class="toolbar">
			<form method="get" class="pull-right">
				<select class="input-small" name="fm">
					<option value="" selected>Tipo de mídia</option>
					<?php
						if(mysql_num_rows($midia_qry)>0){
							$cont=0;
							while($arrMidia = mysql_fetch_array($midia_qry)){
								echo "<option value=".$arrMidia['id_materia'].">".$arrMidia['tipo_midia']."</option>";
								$cont++;
							}
						}
					?>
				</select>
				<select class="input-small" name="fa">
					<option value="" selected>Ano</option>
					<?php
						if(mysql_num_rows($ano_qry)>0){
							$cont=0;
							while($arrAno = mysql_fetch_array($ano_qry)){
								echo "<option value=".$arrAno['anoPub'].">".$arrAno['anoPub']."</option>";
								$cont++;
							}
						}
					?>
				</select>
				<input name="f" type="hidden" value="1" />
				<input type="submit" name="enviar" value="Filtrar" />
			</form>
		</div>
	</body>
</html>